package com.higgins.eventtracking.server.datamaintenance;

import java.util.Date;
import java.util.List;
import java.util.logging.Logger;

import com.higgins.eventtracking.client.AssetTrackingService;
import com.higgins.eventtracking.client.DietTrackingService;
import com.higgins.eventtracking.client.SecurityAccessDeniedException;
import com.higgins.eventtracking.client.datamaintenance.DataMaintenanceService;
import com.higgins.eventtracking.client.dto.AssetDTO;
import com.higgins.eventtracking.client.dto.FinanceGoalDTO;
import com.higgins.eventtracking.client.dto.HealthEventDTO;
import com.higgins.eventtracking.client.dto.InventoryDTO;
import com.higgins.eventtracking.client.dto.MealDTO;
import com.google.gwt.user.server.rpc.RemoteServiceServlet;

/**
 * The server side implementation of the RPC service.
 */
@SuppressWarnings("serial")
public class DataMaintenanceServiceImpl extends RemoteServiceServlet implements DataMaintenanceService {
	private static final Logger log = Logger.getLogger(DataMaintenanceServiceImpl.class.getName());


	@Override
	public Integer retrieveNumberofHealthEvents(String eventType, Boolean clearNulls)	{
		DataMaintenanceDataService dataService = new DataMaintenanceDataService();
		dataService.openPersistenceManager();
		try	{
			
			return dataService.retrieveNumberofHealthEvents(eventType, clearNulls);
		} catch (Exception e)	{
			log.severe(" " + e.toString());
			return null;
		} finally	{
			dataService.closePersistenceManager();
		}
	}


	@Override
	public List<HealthEventDTO> listHealthEventDTOs(String eventType, Boolean clearNulls)
			throws IllegalArgumentException {
		DataMaintenanceDataService dataService = new DataMaintenanceDataService();
		dataService.openPersistenceManager();
		try	{
			return dataService.listHealthEventDTOs(eventType, clearNulls);
		} catch (Exception e)	{
			log.severe(" " + e.toString());
			return null;
		} finally	{
			dataService.closePersistenceManager();
		}
	}


    @Override
    public Integer updateAllRules() throws IllegalArgumentException {
        DataMaintenanceDataService dataService = new DataMaintenanceDataService();
        dataService.openPersistenceManager();
        try {
            return dataService.updateAllRules();
        } catch (Exception e)   {
            log.severe(" " + e.toString());
            return null;
        } finally   {
            dataService.closePersistenceManager();
        }
    }
}
